<?php

$ATQuery = "SELECT * from $airtimes_Table ORDER BY military";
			$resultAT = $db->getAll($ATQuery, DB_FETCHMODE_ASSOC);
			if (DB::isError($resultAT)) {
				die ($resultAT->getMessage());
			}		
		
		
			$UWQuery = "SELECT * FROM $underwriter_Table ORDER BY name asc";
			$resultUW = $db->getAll($UWQuery, DB_FETCHMODE_ASSOC);
			if (DB::isError($resultUW)) {
				die ($resultUW->getMessage());
			}
			
				
		function removeItemFromArray($index){
			if($index == '0'){//item to remove is at begining of array
				array_shift($_SESSION['plannerEntry']);
			}else if((count($_SESSION['plannerEntry']) - $index) == '1'){//item to remove is at end of array
				array_pop($_SESSION['plannerEntry']);
			}else{
				$tempArray1 = array_slice($_SESSION['plannerEntry'], 0, $index);
				$tempArray2 = array_slice($_SESSION['plannerEntry'], ($index + 1));///keep stuff after index position
				$_SESSION['plannerEntry'] = array_merge($tempArray1,$tempArray2);
			}		
					
			if(count($_SESSION['plannerEntry']) == '0'){
				$_SESSION['displayConflicts'] = array();//emopty out array from form action
			}
		}//end function
		
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// BEGIN Remove item from array if remove link is clicked with a sceduling conflict
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		function removeItemFromSearchCriteria($index){
			if($index == '0'){//item to remove is at begining of array
				array_shift($_SESSION['displayConflicts']);
			}else if((count($_SESSION['displayConflicts']) - $index) == '1'){//item to remove is at end of array
				array_pop($_SESSION['displayConflicts']);
			}else{
				$tempArray1 = array_slice($_SESSION['displayConflicts'], 0, $index);
				$tempArray2 = array_slice($_SESSION['displayConflicts'], ($index + 1));///keep stuff after index position
				$_SESSION['displayConflicts'] = array_merge($tempArray1,$tempArray2);
			}		
					
			if(count($_SESSION['displayConflicts']) == '0'){
				$_SESSION['displayConflicts'] = array();//emopty out array from form action
			}
			
			
		}//end function


		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// END Remove item from array if remove link is clicked with a sceduling conflict
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		
		
		
			if(isset($_GET['dropID'])){
				removeItemFromArray($_GET['dropID']);
			}

			if(isset($_GET['searchCriteria'])){
				removeItemFromSearchCriteria(array_search($_GET['searchCriteria'],$_SESSION['displayConflicts']));			
			}
			

			$numFieldsToCreate = count($_SESSION['plannerEntry']);

			if(isset($_SESSION['name'])){//Stuff coming back from the confirm submission
			$changeData = 'true';
			}		
			
			
		
			echo("<script type=\"text/javascript\" language=\"JavaScript\">
			
		function formCheck(){
			
			var cMsg = \"\";

			if(document.form.name.value==\"\"){
			cMsg += \"\\t\" + \"Underwriter Name\" + \"\\n\";
			}
			if(document.form.length.value==\"\"){
			cMsg += \"\\t\" + \"Spot Length\" + \"\\n\";
			}");
			
			$q = 1;
			$i = 0;
			while($i < $numFieldsToCreate){
			echo "
						if(document.form.rate$q.value==\"\" && document.form.trade$q.checked != true){
						cMsg += \"\\t\" + \"Entry Number $q: Rate\" + \"\\n\";
						}else if(document.form.rate$q.value==\"\" && document.form.trade$q.checked == true){
						document.form.rate$q.value=\"NA\"
						}else if(document.form.rate$q.value!=\"NA\" && document.form.rate$q.value!=\"0.00\"){
						document.form.trade$q.checked=false;
						}else{
						document.form.trade$q.checked=true;
						document.form.rate$q.value=\"NA\"
						}";
			
			echo "
			if(document.form.time$q.value==\"not_selected\"){
			cMsg += \"\\t\" + \"Entry Number $q: Time\" + \"\\n\";
			}";
					
			echo "if(document.form.mon$q.checked == false && document.form.tue$q.checked == false && document.form.wed$q.checked == false && document.form.thu$q.checked == false && document.form.fri$q.checked == false && document.form.sat$q.checked == false && document.form.sun$q.checked == false){
			cMsg += \"\\t\" + \"Entry Number $q: Day(s) of Week\" + \"\\n\";
			}";
			++$i;
			++$q;
			}
			echo("if( cMsg != \"\" ){

		 	// we have some deletes to confirm
		
		  	cMsg = \"Please complete the following fields:\\n\\n\" + cMsg + \"\\n\";
		
		  	alert(cMsg)
			}else {
			document.form.submit();
			}										

			
			} 
			// -->
			</script>");		
			

			
		
		//Add UW abreviation to Spot ID field
		echo("<TR><TD valign=\"top\" align=\"center\">");
		echo("<script language=\"JavaScript\" type=\"text/javascript\">
			<!--
			function addAbreviation(){
			document.form.spotID.value = document.form.name.value;
			document.form.action = 'formaction.php?getSpotIDs=true';
			document.form.submit();			
			}
			//-->
			</script>");
			
				echo("<TABLE border=\"1\" width=\"635\" cellpadding=\"0\" cellspacing=\"0\"> \n
					<TR class=\"even\"><TD class=\"formDescriptiveText\">Underwriter:</TD> <TD valign=\"top\" align=\"left\"> \n");
						
						//#####################################
						// Form Item - Underwriter Drop Down List
						//#####################################
					
						if(isset($_SESSION['keepUW'])){
						echo("<select name=\"name\" size=\"1\" onChange = \"addAbreviation()\"><option value=\"\">Choose an underwriter:</option>\n");
						}else{
						echo("<select name=\"name\" size=\"1\" onChange = \"addAbreviation()\"><option value=\"\" selected>Choose an underwriter:</option>\n");
						}
						
					    $x=0;
						while ($x < count($resultUW)) {
						$ID = $resultUW[$x][ID];
						$name = $resultUW[$x][name];
						$abbreviation = $resultUW[$x][abbreviation];
						//if($changeData == 'true'){
							if($name == $_SESSION['keepUW']){
							echo("<option value=\"$abbreviation\" selected>$name</option>\n"); 
							}else{
							echo("<option value=\"$abbreviation\">$name</option>\n"); 
							}
						//}else{
						//echo("<option value=\"$abbreviation\">$name</option>\n"); 
						//}
						++$x;
						}//END LOOP
						echo("</select>\n\n");
						echo("</TD> </TR> \n \n");	

						//#####################################
						// Form Item - Start Date
						//#####################################
						if($_SESSION['PlannerStamp']){
							$EnterTS = $_SESSION['PlannerStamp'];
						}else if(isset($_SESSION['rememberStartStamp'])){
							$EnterTS = $_SESSION['rememberStartStamp'];
						}else{
							$EnterTS = $_SESSION['timestamp'];
						}
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Start Date:</TD>  <TD valign=\"top\" align=\"left\">\n");
						
						$todaysMonth = date("n");
						$todaysDay = date("j");
						$todaysYear = date("Y");
						$monthsText = array("January","February","March","April","May","June","July","August","September","October","November","December");
						
						//Month Drop Down List
						echo("<select name=\"startMonth\" size=\"1\">\n");
						$i = 0;
						$q = 1;
						while($i < 12){
							 if(isset($_POST['startMonth'])){
								if($q == $_POST['startMonth']){
								echo("<option value=\"$q\" selected>$monthsText[$i]</option>\n");
								}else{
								echo("<option value=\"$q\">$monthsText[$i]</option>\n");
								}
							}else{ 
								if($q == date("n",$EnterTS)){
								echo("<option value=\"$q\" selected>$monthsText[$i]</option>\n");
								}else{
								echo("<option value=\"$q\">$monthsText[$i]</option>\n");
								}
							}
						++$i;
						++$q;
						}
						echo("</SELECT>\n\n");
						
						//Day Drop Down List
						echo("<select name=\"startDay\" size=\"1\" >\n");
						$i = 0;
						$q = 1;
						while($i < 31){
							 if(isset($_POST['startDay'])){
								if($q == $_POST['startDay']){
								echo("<option value=\"$q\" selected>$q</option>\n");
								}else{
								echo("<option value=\"$q\">$q</option>\n");
								}
							}else{ 
								if($q == date("j",$EnterTS)){
								echo("<option value=\"$q\" selected>$q</option>\n");
								}else{
								echo("<option value=\"$q\">$q</option>\n");
								}
							}
						++$i;
						++$q;
						}
						echo("</SELECT>\n\n");
						
						
						//Year Drop Down List
						echo("<select name=\"startYear\" size=\"1\"> \n");
						if(!isset($_POST['startYear'])){
						
								for ($i = $yearToStartRecords; $i < date("Y"); $i++) {
											if($i == date("Y",$EnterTS)){
											echo("<option value=\"" . $i . "\" selected>" . $i . "</option>\n");
											}else{
											echo("<option value=\"" . $i . "\">" . $i . "</option>\n");
											}
								} 
								
							
									$i = 0;
									while($i < 5){
											$futureYears = ($todaysYear + $i);
											if($futureYears == date("Y",$EnterTS)){
											echo("<option value=\"$futureYears\" selected>$futureYears</option> \n");
											}else{
											echo("<option value=\"$futureYears\">$futureYears</option> \n");
											}
									++$i;
									}
						 }else{
						
							for ($i = $yearToStartRecords; $i < date("Y"); $i++) {
										if($i == $_POST['startYear']){
										echo("<option value=\"" . $i . "\" selected>" . $i . "</option>\n");
										}else{
										echo("<option value=\"" . $i . "\">" . $i . "</option>\n");
										}
							} 
							
													
								$i = 0;
								while($i < 5){
									if(($todaysYear + $i) == $_POST['startYear']){
										echo("<option value=\"" . ($todaysYear + $i) . "\" selected>" . ($todaysYear + $i) . "</option> \n");
									}else{
										echo("<option value=\"" . ($todaysYear + $i) . "\">" . ($todaysYear + $i) . "</option> \n");
									}
								++$i;
								}
						
						} 
						echo("</SELECT> \n");
						
					    echo("</TD></TR> \n \n");	
				

						//#####################################
						//FORM ITEM - End Date						
						//#####################################
					    echo("<TR class=\"even\" ><TD class=\"formDescriptiveText\">End Date:</TD>  <TD valign=\"top\" align=\"left\"> \n");

						//Month Drop Down List
						echo("<select name=\"endMonth\" size=\"1\">\n");
						
							if(!isset($_SESSION['endMonth'])){
							echo("<option value=\"NA\" selected>NA</option> \n");//first time you come to form from planner
							}else if($_SESSION['endMonth'] == 'NA'){
							echo("<option value=\"NA\" selected>NA</option> \n");
							}else{
							echo("<option value=\"NA\">NA</option> \n");
							}
							
						$i = 0;
						$q = 1;
						while($i < 12){
							if(isset($_SESSION['endMonth'])){
								if($q == $_SESSION['endMonth']){
								echo("<option value=\"$q\" selected>$monthsText[$i]</option>\n");
								}else{
								echo("<option value=\"$q\">$monthsText[$i]</option>\n");
								}
							}else{
							echo("<option value=\"$q\">$monthsText[$i]</option> \n");
							}
						++$i;
						++$q;
						}
						echo("</SELECT>\n\n");						
						
						
						
						
						//Day Drop Down List
						echo("<select name=\"endDay\" size=\"1\"> \n");
							if(!isset($_SESSION['endDay'])){
							echo("<option value=\"NA\" selected>NA</option> \n");
							}else if($_SESSION['endDay'] == 'NA'){
							echo("<option value=\"NA\" selected>NA</option> \n");
							}else{
							echo("<option value=\"NA\">NA</option> \n");
							}						
						$i = 0;
						$q = 1;
						while($i < 31){
						//echo("<option value=\"$q\">$q</option> \n");
							if(isset($_SESSION['endDay'])){
								if($q == $_SESSION['endDay']){
								echo("<option value=\"$q\" selected>$q</option>\n");
								}else{
								echo("<option value=\"$q\">$q</option>\n");
								}
							}else{
							echo("<option value=\"$q\">$q</option> \n");
							}
						
						++$i;
						++$q;
						}
						echo("</SELECT> \n \n");


									
						//Year Drop Down List
						echo("<select name=\"endYear\" size=\"1\"> \n");
						if(!isset($_SESSION['endYear'])){
							echo("<option value=\"NA\" selected>NA</option> \n");
							
						for ($i = $yearToStartRecords; $i < date("Y"); $i++) {
									echo("<option value=\"" . $i . "\">" . $i . "</option>\n");
						} 
							echo("<option value=\"$todaysYear\">$todaysYear</option> \n");
							$i = 1;
							while($i < 5){
									$futureYears = ($todaysYear + $i);
									echo("<option value=\"$futureYears\">$futureYears</option> \n");
							++$i;
							}
						}else{
							if($_SESSION['endYear'] == 'NA'){
							echo("<option value=\"NA\" selected>NA</option> \n");
							}else{
							echo("<option value=\"NA\">NA</option> \n");
							}
							
 						for ($i = $yearToStartRecords; $i < date("Y"); $i++) {
									if($i == $_SESSION['endYear']){
									echo("<option value=\"" . $i . "\" selected>" . $i . "</option>\n");
									}else{
									echo("<option value=\"" . $i . "\">" . $i . "</option>\n");
									}
						} 							
							$i = 0;
							while($i < 5){
								if(($todaysYear + $i) == $_SESSION['endYear']){
									echo("<option value=\"" . ($todaysYear + $i) . "\" selected>" . ($todaysYear + $i) . "</option> \n");
								}else{
									echo("<option value=\"" . ($todaysYear + $i) . "\">" . ($todaysYear + $i) . "</option> \n");
								}
							++$i;
							}
						
						}
						echo("</SELECT> \n");

					    echo("</TD></TR> \n");	
		
						//#####################################
						//FORM ITEM - Length						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Spot Length:</TD>  <TD class=\"formElementTextLeft\"> \n");
						if(!isset($_SESSION['length'])){
						echo("<INPUT name=\"length\" type=\"text\"> (Seconds) \n");
						}else{
						echo("<INPUT name=\"length\" type=\"text\" value = \"" . $_SESSION['length'] . "\"> (Seconds) \n");
						}
					    echo("</TD></TR> \n");	
				
						//#####################################
						//FORM ITEM - ID/AV# 						
						//#####################################				
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Spot ID:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						if(!isset($_SESSION['spotID'])){
						echo("<INPUT name=\"spotID\" type=\"text\" value=\"\"> <FONT size=\"-1\"></FONT> \n");
						}else{
						echo("<INPUT name=\"spotID\" type=\"text\" value=\"" . $_SESSION['spotID'] . "\"> <FONT size=\"-1\"></FONT> \n");
						}
					    echo("</TD></TR> \n \n");	
						
						
						//#####################################
						//FORM ITEM - TYPE: EPSA or UW 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Type:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						echo("<select name=\"type\" size=\"1\" > \n");
						if(!isset($_SESSION['type'])){
						echo("<option value=\"UW\" selected>Underwriter</option> \n");
 						echo("<option value=\"EPSA\">EPSA</option> \n");
						}else{
							if($_SESSION['type'] == 'UW'){
							echo("<option value=\"UW\" selected>Underwriter</option> \n");
 							echo("<option value=\"EPSA\">EPSA</option> \n");
							}else{
							echo("<option value=\"UW\">Underwriter</option> \n");
 							echo("<option value=\"EPSA\" selected>EPSA</option> \n");
							}
						}
						echo("</SELECT></TD></TR> \n \n");		
						
						
						
						
					
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//BEGIN JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						echo"<script language=\"JavaScript\" type=\"text/javascript\">
						<!--
						//Array to hold days and values
						
						function timeEntry(time,mon,tue,wed,thu,fri,sat,sun){
						this.time = time;
						this.mon = mon;
						this.tue = tue;
						this.wed = wed;
						this.thu = thu;
						this.fri = fri;
						this.sat = sat;
						this.sun = sun;
						}
						
						var javaAT = new Array(" . count($resultAT) . ");
						";
						
						
						$a = 0;
						while($a < count($resultAT)){
						echo "javaAT[$a] = new timeEntry(\"".$resultAT[$a][hour].":".$resultAT[$a][minute].":".$resultAT[$a][ampm]."\",\"".$resultAT[$a][mon]."\",\"".$resultAT[$a][tue]."\",\"".$resultAT[$a][wed]."\",\"".$resultAT[$a][thu]."\",\"".$resultAT[$a][fri]."\",\"".$resultAT[$a][sat]."\",\"".$resultAT[$a][sun]."\");\n";
						++$a;
						}
					
						echo "function nullDays(pointer){
						var dropDown = eval(\"document.form.time\" + pointer + \".value\");
						
						for (var q=0; q <".count($resultAT)."; q++) {
							if(dropDown == javaAT[q].time){
							
								if(javaAT[q].mon != 'true'){
								var mon = \"document.form.mon\" + pointer + \".checked = false\";
								eval(mon);
								var mon = \"document.form.mon\" + pointer + \".disabled = true\";
								eval(mon);
								}else{
								var mon = \"document.form.mon\" + pointer + \".disabled = false\";
								eval(mon);	
								}
								
								if(javaAT[q].tue != 'true'){
								var tue = \"document.form.tue\" + pointer + \".checked = false\";
								eval(tue);								
								var tue = \"document.form.tue\" + pointer + \".disabled = true\";
								eval(tue);
								}else{
								var tue = \"document.form.tue\" + pointer + \".disabled = false\";
								eval(tue);	
								}								
								
								if(javaAT[q].wed != 'true'){
								var wed = \"document.form.wed\" + pointer + \".checked = false\";
								eval(wed);								
								var wed = \"document.form.wed\" + pointer + \".disabled = true\";
								eval(wed);
								}else{
								var wed = \"document.form.wed\" + pointer + \".disabled = false\";
								eval(wed);	
								}								
									
								if(javaAT[q].thu != 'true'){
								var thu = \"document.form.thu\" + pointer + \".checked = false\";
								eval(thu);								
								var thu = \"document.form.thu\" + pointer + \".disabled = true\";
								eval(thu);
								}else{
								var thu = \"document.form.thu\" + pointer + \".disabled = false\";
								eval(thu);	
								}								
								
								if(javaAT[q].fri != 'true'){
								var fri = \"document.form.fri\" + pointer + \".checked = false\";
								eval(fri);								
								var fri = \"document.form.fri\" + pointer + \".disabled = true\";
								eval(fri);
								}else{
								var fri = \"document.form.fri\" + pointer + \".disabled = false\";
								eval(fri);	
								}								
									
								if(javaAT[q].sat != 'true'){
								var sat = \"document.form.sat\" + pointer + \".checked = false\";
								eval(sat);								
								var sat = \"document.form.sat\" + pointer + \".disabled = true\";
								eval(sat);
								}else{
								var sat = \"document.form.sat\" + pointer + \".disabled = false\";
								eval(sat);	
								}							
									
								if(javaAT[q].sun != 'true'){
								var sun = \"document.form.sun\" + pointer + \".checked = false\";
								eval(sun);								
								var sun = \"document.form.sun\" + pointer + \".disabled = true\";
								eval(sun);
								}else{
								var sun = \"document.form.sun\" + pointer + \".disabled = false\";
								eval(sun);	
								}								

							break;
							}
						}
						
						//alert(javaAT[10].time);
						//alert(mon);
						}
						//-->
						</script>";
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//END JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//BEGIN JAVASCRIPT FUNCTION TO ENABLE ALL CHECKBOXES
						//++++++++++++++++++++++++++++++++++++++++++++++++++
						echo "<script language=\"JavaScript\" type=\"text/javascript\">
						<!--
							function resetForm(){
							for (var q=0; q < document.form.elements.length; q++) {
							 // get each element of form form
							 var e = document.form.elements[q];
			
							 if( e.type == \"checkbox\"){
							 e.disabled = false;
							}
							

			
						}//end loop

						document.form.reset();
						
						for (var q=0; q < document.form.elements.length; q++) {
							 // get each element of form form
							 var e = document.form.elements[q];
			
							 if(e.name.indexOf('time') != -1){
							 var text = e.name;
							 var pointer = text.substring(4,text.length);
							 //alert(pointer);
							 nullDays(pointer);
							}
							

			
						}//end loop
						
						}//end function
						//-->
						</script> ";
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//END JAVASCRIPT FUNCTION TO ENABLE ALL CHECKBOXES
						//++++++++++++++++++++++++++++++++++++++++++++++++++		

		//BEGIN ENTER MULTIPLE FIELDS
			$i = 0;
			$q = 1;
			while ($i < $numFieldsToCreate){
			//+++++++++++++++++++++++++++++++++++++
			//BEGIN REPEATING FIELDS FOR MULTIPLE ENTRIES
			//+++++++++++++++++++++++++++++++++++++
					    echo("<TR class=\"blockHeader\"><TD valign=\"top\" align=\"right\">ENTRY NUMBER $q:</TD>  <TD valign=\"top\" align=\"right\" class=\"dropButton\"> \n");
						
						$time = $_SESSION['verifyTimeArray']["$i"];
						$hour = substr($time, 0, 2);
						$minute = substr($time, 3, 2);
						$ampm = substr($time, 6, 2);
						
							//++++++++++++++++++++++++++++++++++++++++
							//Also used in FORM ITEM - Air Time Below
							$plannerHour = substr($_SESSION['plannerEntry'][$i]["military"],0,2);
							$plannerMinute = substr($_SESSION['plannerEntry'][$i]["military"],3,2);
							$plannerSeconds =substr($_SESSION['plannerEntry'][$i]["military"],6,2);
							if($plannerHour < '12'){
							$plannerAMPM = 'AM';
							}else{
							$plannerAMPM = 'PM'; 
							}
							$myNewMilitary = $plannerHour . ":" . $plannerMinute . ":".$plannerSeconds;
							//END++++++++++++++++++++++++++++++++++
						
						if(count($_SESSION['displayConflicts']) > '0'){ 
							$searchCriteria = "$plannerHour:$plannerMinute:$plannerSeconds:$plannerAMPM";

							if(array_search($searchCriteria,$_SESSION['displayConflicts']) !== FALSE){
									echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><TR><TD align=\"left\" width=\"20\"><IMG src=\"$imagesDirectory/warning2.gif\" border=\"0\" width=\"18\" height=\"18\"> </TD><TD align=\"left\" class=\"conflictWarning\" nowrap> Scheduling Conflict</TD>";
									//if(count($_SESSION['plannerEntry']) != 0){
										echo"<TD align=\"right\" class=\"dropButton\"><A HREF=\"index.php?ID=0&amp;subMenu=2&amp;action=enter&amp;dropID=$i&amp;searchCriteria=$searchCriteria\">Remove</A></TD>";
									//}
								echo"</TR></TABLE>";

							}else{
								echo "<A HREF=\"index.php?ID=0&amp;subMenu=2&amp;action=enter&amp;dropID=$i\">Remove</A>";
							}

						}else if(count($_SESSION['plannerEntry']) != 0){
							echo "<A HREF=\"index.php?ID=0&amp;subMenu=2&amp;action=enter&amp;dropID=$i\">Remove</A>";
						}
						
						echo("</TD></TR> \n \n");	
						
						//#####################################
						//FORM ITEM - Air Time 						
						//#####################################				
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Air time:</TD>  <TD valign=\"top\" align=\"left\"> \n");

							//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
							//ID for adding info to $_SESSION['plannerEntry'] to remember info
							echo"<input name=\"rememberTime$q\" type=\"hidden\" value=\"$i\">";
							//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						
							echo("<select name=\"time$q\" size=\"1\" onChange=\"nullDays($q)\"> \n");
							echo("<option value=\"not_selected\">Choose</option> \n");   
							$r=0;
							while ($r < count($resultAT)) {
							$hour = $resultAT[$r][hour];
							$minute = $resultAT[$r][minute];
							$ampm = $resultAT[$r][ampm];
							
							//if($resultAT[$r][hour] != $resultAT[$r+1][hour] && $resultAT[$r][minute] != $resultAT[$r+1][minute]){//keep half minute times from duplicating in list
							
								if($resultAT[$r]["military"] == $myNewMilitary){
								$plannerMon = $resultAT[$r][mon];
								$plannerTue = $resultAT[$r][tue];
								$plannerWed = $resultAT[$r][wed];
								$plannerThu = $resultAT[$r][thu];
								$plannerFri = $resultAT[$r][fri];
								$plannerSat = $resultAT[$r][sat];
								$plannerSun = $resultAT[$r][sun];
								echo("<option value=\"$hour:$minute:$ampm\" selected>$hour:$minute $ampm</option> \n");   
								}else if($changeData != 'true'){
								echo("<option value=\"$hour:$minute:$ampm\">$hour:$minute $ampm</option> \n");   
								}else if($plannerHour == $hour && $plannerMinute == $minute && $plannerAMPM == $ampm){
								echo("<option value=\"$hour:$minute:$ampm\" selected>$hour:$minute $ampm</option> \n");   
								}else{
								echo("<option value=\"$hour:$minute:$ampm\">$hour:$minute $ampm</option> \n");   
								}     
								
							//}
								                                                                                                                                                                                                                                                                                                                                   
								++$r;
							}//END Loop
							echo("</SELECT> \n \n");				


						//if($changeData != 'true'  && $plannerSeconds != '30'){
							//echo(" : <select name=\"seconds$q\" size=\"1\"><option value=\"00\" selected>00 Seconds</option><option value=\"30\">30 Seconds</option></SELECT> &nbsp; \n \n");				
						//}else{
							echo(" : <select name=\"seconds$q\" size=\"1\">");
							if($plannerSeconds == '30'){
							echo("<option value=\"00\">00 Seconds</option><option value=\"30\" selected>30 Seconds</option></SELECT> &nbsp; \n \n");
							}else{
							echo("<option value=\"00\" selected>00 Seconds</option><option value=\"30\">30 Seconds</option></SELECT> &nbsp; \n \n");
							}				
						//}
										    
						echo("</TD></TR> \n \n");		
						
						
						//#####################################
						//FORM ITEM - Days of Week 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Day(s) of week:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						echo("<TABLE width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><TR> \n");
						//if($changeData != 'true'){
							if(array_search("mon",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$q\" type=\"checkbox\" value=\"true\" checked>Mon &nbsp;&nbsp;</TD> \n");
							}else if($plannerMon == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$q\" type=\"checkbox\" value=\"true\">Mon &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$q\" type=\"checkbox\" value=\"true\" disabled>Mon &nbsp;&nbsp;</TD> \n");
							}

							if(array_search("tue",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$q\" type=\"checkbox\" value=\"true\" checked>Tue &nbsp;&nbsp;</TD> \n");
							}else if($plannerTue == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$q\" type=\"checkbox\" value=\"true\">Tue &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$q\" type=\"checkbox\" value=\"true\" disabled>Tue &nbsp;&nbsp;</TD> \n");
							}
							
							if(array_search("wed",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$q\" type=\"checkbox\" value=\"true\" checked>Wed &nbsp;&nbsp;</TD> \n");
							}else if($plannerWed == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$q\" type=\"checkbox\" value=\"true\">Wed &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$q\" type=\"checkbox\" value=\"true\" disabled>Wed &nbsp;&nbsp;</TD> \n");
							}
							
							if(array_search("thu",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$q\" type=\"checkbox\" value=\"true\" checked>Thu &nbsp;&nbsp;</TD> \n");
							}else if($plannerThu == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$q\" type=\"checkbox\" value=\"true\">Thu &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$q\" type=\"checkbox\" value=\"true\" disabled>Thu &nbsp;&nbsp;</TD> \n");
							}
							
							if(array_search("fri",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$q\" type=\"checkbox\" value=\"true\" checked>Fri &nbsp;&nbsp;</TD> \n");
							}else if($plannerFri == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$q\" type=\"checkbox\" value=\"true\">Fri &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$q\" type=\"checkbox\" value=\"true\" disabled>Fri &nbsp;&nbsp;</TD> \n");
							}
							
							if(array_search("sat",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$q\" type=\"checkbox\" value=\"true\" checked>Sat &nbsp;&nbsp;</TD> \n");
							}else if($plannerSat == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$q\" type=\"checkbox\" value=\"true\">Sat &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$q\" type=\"checkbox\" value=\"true\" disabled>Sat &nbsp;&nbsp;</TD> \n");
							}
							
							if(array_search("sun",$_SESSION['plannerEntry'][$i][days]) !== FALSE){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$q\" type=\"checkbox\" value=\"true\" checked>Sun &nbsp;&nbsp;</TD> \n");
							}else if($plannerSun == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$q\" type=\"checkbox\" value=\"true\">Sun &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$q\" type=\"checkbox\" value=\"true\" disabled>Sun &nbsp;&nbsp;</TD> \n");
							}

						echo("</TR></TABLE> \n");
						echo("</TD></TR> \n \n");	
						



						//#####################################
						//FORM ITEM - Rate 						
						//#####################################				
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Rate:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						//if($changeData != 'true'){
						//echo("<INPUT name=\"rate$q\" type=\"text\"> \n");
						//}else{
						if($_SESSION['plannerEntry'][$i][trade] == 'true'){
							echo("<INPUT name=\"rate$q\" type=\"text\" value=\"NA\"> \n"); 
						}else{
							echo("<INPUT name=\"rate$q\" type=\"text\" value=\"" . $_SESSION['plannerEntry'][$i][rate] . "\"> \n"); 
						}
					    echo("</TD></TR> \n \n");						
						

												
						
						//#####################################
						//FORM ITEM - Live Read 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Is this spot a live read?</TD>  <TD class=\"formElementTextLeft\"> \n");
						//if($changeData != 'true'){
						//echo("<INPUT name=\"live$q\" type=\"checkbox\" value=\"true\"> <FONT size=\"-1\">Yes</FONT> \n");
						//}else{
							if($_SESSION['plannerEntry'][$i][live] == 'true'){
							echo("<INPUT name=\"live$q\" type=\"checkbox\" value=\"true\" checked> Yes \n");
							}else{
							echo("<INPUT name=\"live$q\" type=\"checkbox\" value=\"true\"> Yes \n");
							}
						//}
					    echo("</TD></TR> \n \n");						
						
						
    					//#####################################
						//FORM ITEM - TRADE? 						
						//#####################################	
						echo("<script language=\"JavaScript\" type=\"text/javascript\"> \n
						<!--
						function noRate$q(){  \n
							if(document.form.rate$q.value == \"NA\"){
							document.form.rate$q.value = \"\";						
							}else{
							document.form.rate$q.value=\"NA\";  \n
							}
						}  \n
						//-->  \n
						</script>  \n");
						
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Is this spot a trade?</TD>  <TD class=\"formElementTextLeft\">  \n");
						//if($changeData != 'true'){
						//echo("<INPUT name=\"trade$q\" type=\"checkbox\" value=\"true\" onClick=\"noRate$q()\"> <FONT size=\"-1\">Yes</FONT> \n");
						//}else{
							if($_SESSION['plannerEntry'][$i][trade] == 'true'){
							echo("<INPUT name=\"trade$q\" type=\"checkbox\" value=\"true\" onClick=\"noRate$q()\" checked> Yes \n");
							}else{
							echo("<INPUT name=\"trade$q\" type=\"checkbox\" value=\"true\" onClick=\"noRate$q()\"> Yes \n");
							}
						//}
					    echo("</TD> </TR> \n");		
						
			//+++++++++++++++++++++++++++++++++++++
			//END REPEATING FIELDS FOR MULTIPLE ENTRIES
			//+++++++++++++++++++++++++++++++++++++												
			++$i;
			++$q;
			}
		

		echo "</TABLE>";
		if($_SESSION['PlannerStamp']){
		echo"<INPUT name=\"PlannerStamp\" type=\"hidden\" value=\"".$_SESSION['PlannerStamp']."\">";
		}else if($_POST['PlannerStamp']){
		echo"<INPUT name=\"PlannerStamp\" type=\"hidden\" value=\"".$_POST['PlannerStamp']."\">";
		}
		echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><INPUT name=\"mulitpleHighNumber\" type=\"hidden\" value=\"$numFieldsToCreate\"><INPUT name=\"myAction\" type=\"hidden\" value=\"generateVerification\">");
		if(count($_SESSION['plannerEntry']) == '0'){
		echo"<INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" disabled onClick = \"formCheck()\">";
		}else{
		echo"<INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick = \"formCheck()\">";
		}
		echo(" &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"button\" class=\"inputButton\"  value=\"Reset\" onClick=\"resetForm()\"></TD></FORM></TR>");
		echo("</TABLE>");	
		
		//unset($_SESSION['numFields']);		

?>